#include<stdio.h>
void Swap(int* a, int* b)
{
	int tmp = *a;
	*a = *b;
	*b = tmp;
}
void SelectSort(int* arr, int n)
{
	int begin = 0;
	int end = n - 1;
	
	while (begin < end)
	{
		int maxi = begin;
		int mini = begin;
		int flag1 = 1;
		int flag2 = 1;
		for (int i = begin; i <= end; i++)
		{
			if (arr[i] > arr[maxi])
			{
				flag1 = 0;
				maxi = i;
			}
			if (arr[i] < arr[mini])
			{
				flag2 = 0;
				mini = i;
			}
		}
		if (flag1 == 0)
		{
			Swap(&arr[begin], &arr[mini]);
			++begin;
		}
		if (flag2 == 0)
		{
			Swap(&arr[end], &arr[maxi]);
			--end;
		}
	}
}
void PrintArr(int* arr, int n)
{
	for (int i = 0; i < n; i++)
	{
		printf("%d ", arr[i]);
	}
}
int main()
{
	int arr[] = { 9,8,7,6,5,4,3,2,1,0 };
	SelectSort(arr, sizeof(arr) / sizeof(int));
	PrintArr(arr, sizeof(arr) / sizeof(int));

	return 0;
}